package fly

import "time"
import "gorm.io/gorm"
import "go_part/utils"
//import "fmt"

type AirportInfo struct{
	gorm.Model
	Name string
	DeviceID string
	LevelLocalID string
	CompanyID string
	DeviceTypeID string
	PositionID string
	Identity string
	Longitude string
	Latitude string
	LoginTime time.Time
	RealMessageID string
	IsLogout bool
	IsPrevent bool
	DeviceInfo string
 }

 func (table *AirportInfo) TableName() string {

	return "airport_info_basic"
}

func GetAirportInfoList() []*AirportInfo { 
	data := make([]*AirportInfo,10)
	utils.DB.Find(&data)
	// for _,v : = range data {
	// 	fmt.Println(v)
	// }
	return data
}

func FindAirportInfoByName(name string) AirportInfo {
	user := AirportInfo{}
	utils.DB.Where("name = ?",name).Find(&user)
	return user
}

func FindAirportInfoByID(id uint) AirportInfo {
	user := AirportInfo{}
	utils.DB.Where("id = ?",id).First(&user)
	return user
}

func FindAirportInfoByDeviceID(id string) AirportInfo {
	user := AirportInfo{}
	utils.DB.Where("device_id = ?",id).First(&user)
	return user
}

func FindAirportByTypeIDAndCompanyID(id string,CompanyID string) []*AirportInfo {
	user := make([]*AirportInfo,100)
	utils.DB.Where("level_local_id = ? and company_id = ?",id,CompanyID).Find(&user)
	return user
}

func CreateAirportInfo(user AirportInfo) *gorm.DB {
	
	return utils.DB.Create(&user)
}

func DeleteAirportInfo(user AirportInfo) *gorm.DB {
	
	return utils.DB.Delete(&user)
}

func UpdateAirportInfo(user AirportInfo) *gorm.DB {
	
	return utils.DB.Model(&user).Updates(AirportInfo{Name: user.Name, Longitude: user.Longitude, Latitude: user.Latitude,PositionID: user.PositionID,  DeviceInfo: user.DeviceInfo})
}